<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/1/5
  Time: 8:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@include file="header.jsp" %>
    <script src="/static/echarts.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
    <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
    <div id="main" style="width: 600px;height:400px;"></div>
    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        $.post(
            '/echarts/selectOrderProductCount',
            function(jsonResult) {
                console.log(jsonResult);
                // [{name: 'Apple iPhone 7 Plus', value: 5},{name: 'zhangsan', value: 3}]
                var xArray = new Array();
                var yArray = new Array();
                var list = jsonResult.data;
                for (var i = 0; i < list.length; i++) {
                    xArray.push(list[i].name);
                    yArray.push(list[i].value);
                }

                // 指定图表的配置项和数据
                var option = {
                    title: {
                        text: 'ECharts 入门示例'
                    },
                    tooltip: {},
                    legend: {
                        data: ['销量']
                    },
                    xAxis: {
                        data: xArray
                    },
                    yAxis: {},
                    series: [
                        {
                            name: '销量',
                            type: 'bar',
                            data: yArray
                        }
                    ]
                };

                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);


            },
            'json'
        );


    </script>
</body>
</html>
